package leetcode.offer_two_special.string;

/**
 * @author mazouri
 * @create 2021-09-06 20:22
 */
public class _19_validPalindrome {
    /**
     * @param s 由小写英文字母组成
     * @return
     */
    public boolean validPalindrome(String s) {
        int start = 0;
        int end = s.length() - 1;

        while (start < end) {
            if (s.charAt(start) != s.charAt(end)) break;
            start++;
            end--;
        }

        return start == s.length() / 2 || isPalindrome(s, start, end - 1)
                || isPalindrome(s, start + 1, end);
    }

    private boolean isPalindrome(String s, int start, int end) {
        while (start < end) {
            if (s.charAt(start) != s.charAt(end)) break;

            start++;
            end--;
        }
        // aba 结束条件为相等  abba结束条件为start>end
        return start>=end;
    }
}
